<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('会员课程列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="layui-form form-inline">
            <a class="btn btn-success" onclick="openCouList()">
                <i class="fa fa-plus"></i> 添加
            </a>&nbsp;
            <input type="text" class="form-control mr-1" name="courseName" placeholder="课程名称">
            <select class="form-control mr-1" name="subjectId">
                <option value="0">专业</option>
                <option th:each="subject : ${subjectList}" th:value="${subject.subjectId}" th:text="${subject.subjectName}">室内设计</option>
            </select>
            <button type="button" class="btn btn-primary mr-1" onclick="$.table.search()">
                <i class="fa fa-search"></i>
                搜索
            </button>
            <button type="button" class="btn btn-default" onclick="$.form.reset()">
                <i class="fa fa-refresh"></i>
                重置
            </button>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var typeId = [[${typeId}]];
    var prefix = "/type";
    $(function() {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: "/member/course/list.json?typeId=" + typeId,
            modalName: "会员类型",
            columns: [
                {
                    field: 'courseId',
                    title: '课程ID',
                    width: '80px'
                },
                {
                    field: 'courseName',
                    title: '课程名称'
                },
                {
                    field: 'categoryName',
                    title: '专业',
                    width: '120px'
                },
                {
                    field: 'price',
                    title: '价格',
                    width: '80px',
                    formatter: function (value, row, index) {
                        return value / 100
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    width: '80px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="delCourse(\'' + row.courseId + '\')"><i class="fa fa-remove"></i>移除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //重置
    function ResetForm() {
        $("#treeId").val(0);
        $.form.reset();
    }

    //添加课程列表
    function openCouList() {
        var w = document.documentElement.clientWidth || document.body.clientWidth;
        layer.open({
            type: 2,
            area: [w > 1024 ? '1024px' : '100%', '550px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "添加课程",
            content: "/course/select.html",
            shadeClose: true
        });
    }

    //添加课程
    function addCou(couArr) {
        var data = {'typeId': typeId, 'courseIds': couArr.join(',')};
        console.log(data);
        $.operate.submit('/member/course/add.json', 'post', 'json', data);
    }

    //删除课程
    function delCourse(courseId) {
        $.modal.confirm("请确定执行删除课程操作", function () {
            var data = {"courseId": courseId, "typeId": typeId};
            $.operate.submit("/member/course/del.json", "post", "json", data);
        });
    }
</script>
</body>
</html>